import java.util.InputMismatchException;
import java.util.Scanner;

public class Manage {
    static Manager manager = Manager.getInstance();

    public static void passwordManage() {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            try {
                System.out.println("请选择 1 更改管理员密码 2 重置客户密码");
                int input = scanner.nextInt();
                if (input == 1) {
                    manager.changeAdminPassword();
                    System.out.println("修改管理员密码成功");
                    ObjectSystem.managerMenu();
                } else if (input == 2) {
                    System.out.println("请输入客户ID");
                    String customerId = scanner.next();
                    System.out.println("请输入新密码");
                    String newPassword = scanner.next();
                    Customer customer = manager.getCustomerById(customerId);
                    if (customer != null) {
                        manager.resetUserPassword(customer, newPassword);
                        System.out.println("修改客户密码成功");
                    } else {
                        System.out.println("客户ID不存在");
                    }
                    ObjectSystem.managerMenu();
                } else {
                    System.out.println("输入有误，请重新输入");
                }
            } catch (InputMismatchException e) {
                System.out.println("输入有误，请重新输入");
                scanner.nextLine();
            }
        }
    }

    public static void customerManage() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请选择 1 列出客户信息 2 删除客户信息 3 查询客户信息");
        int input = scanner.nextInt();
        if (input == 1) {
            manager.listAllCustomers();
            ObjectSystem.managerMenu();
        } else if (input == 2) {
            System.out.println("请输入要删除的客户ID");
            String id = scanner.next();
            manager.deleteCustomer(id);
            ObjectSystem.managerMenu();
        } else if (input == 3) {
            System.out.println("请输入要查找的客户ID");
            String id = scanner.next();
            manager.searchCustomer(id);
            ObjectSystem.managerMenu();
        } else {
            System.out.println("输入有误，请重新输入");
        }
    }

    public static void productManage() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请选择 1 列出商品信息 2 添加商品信息 3 修改商品信息 4 删除商品信息");
        int input = scanner.nextInt();
        if (input == 1) {
            Manager.listAllProducts();
            ObjectSystem.managerMenu();
        } else if (input == 2) {
            System.out.println("添加商品信息");
            System.out.println("请输入商品编号");
            String newId = scanner.next();
            System.out.println("请输入商品名称");
            String newName = scanner.next();
            System.out.println("请输入生产厂家");
            String newManufacturer = scanner.next();
            System.out.println("请输入生产日期");
            String newDate = scanner.next();
            System.out.println("请输入商品型号");
            String newModel = scanner.next();
            System.out.println("请输入商品进货价");
            Double newPurchasePrice = scanner.nextDouble();
            System.out.println("请输入商品零售价");
            Double newRetailPrice = scanner.nextDouble();
            System.out.println("请输入商品数量");
            int newQuantity = scanner.nextInt();
            Product product = new Product(newId, newName, newManufacturer, newDate, newModel, newPurchasePrice, newRetailPrice, newQuantity);
            Manager.addProduct(product);
            ObjectSystem.managerMenu();
        } else if (input == 3) {
            System.out.println("请输入要查修改的商品ID");
            String id = scanner.next();
            System.out.println("请输入商品名称");
            String newName = scanner.next();
            System.out.println("请输入生产厂家");
            String newManufacturer = scanner.next();
            System.out.println("请输入生产日期");
            String newDate = scanner.next();
            System.out.println("请输入商品型号");
            String newModel = scanner.next();
            System.out.println("请输入商品进货价");
            Double newPurchasePrice = scanner.nextDouble();
            System.out.println("请输入商品零售价");
            Double newRetailPrice = scanner.nextDouble();
            System.out.println("请输入商品数量");
            int newQuantity = scanner.nextInt();
            Product product = new Product(id, newName, newManufacturer, newDate, newModel, newPurchasePrice, newRetailPrice, newQuantity);
            Manager.updateProduct(id, product);
            ObjectSystem.managerMenu();
        } else if (input == 4) {
            System.out.println("请输入要删除的商品ID");
            String id = scanner.next();
            Manager.deleteProduct(id);
            ObjectSystem.managerMenu();
        } else {
            System.out.println("输入有误，请重新输入");
        }
    }
}

